package com.hdd.art.biz.painting.controller;


import com.hdd.art.biz.member.dto.MemberDo;
import com.hdd.art.biz.member.dto.VerifyListDo;
import com.hdd.art.biz.painting.dto.*;
import com.hdd.art.biz.painting.entity.PaintingMedia;
import com.hdd.art.biz.painting.entity.PaintingWorks;
import com.hdd.art.biz.painting.service.PaintingMediaService;
import com.hdd.art.biz.painting.service.PaintingPraisesService;
import com.hdd.art.biz.painting.service.PaintingWorksService;
import com.hdd.art.dto.AppResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.scene.input.DataFormat;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 作品表 前端控制器
 * </p>
 *
 * @author fang
 * @since 2021-06-27
 */
@RestController
@RequestMapping("/painting")
@Api(value = "作品模块",tags = {"作品模块"})
public class PaintingWorksController {

    @Autowired
    private PaintingWorksService worksService;

    @Autowired
    private PaintingPraisesService praisesService;

    @PostMapping("/info")
    @ApiOperation(value = "作品详情" ,notes = "")
    public AppResponse info(@Valid @RequestBody PaintingWorksDto dto ){
        AppResponse response = new AppResponse();

        PaintingWorks paintingWorks =   worksService.findPaintingWorks(dto.getWorkId());
        if(null == paintingWorks){
            return response;
        }

        PaintingWorksInfoVo vo = new PaintingWorksInfoVo();
        BeanUtils.copyProperties(paintingWorks,vo);
        vo.setCreateTime("2020-07-20");
        vo.setSize("100x100");
        vo.setMedium(paintingWorks.getMedium());
        response.setItem(vo);
        return response;
    }


    @PostMapping("/worksManage")
    @ApiOperation(value = "作品管理-列表(馆长) '0待审核，1通过 -1 拒绝 2参展中 3 已撤展'," ,notes = "")
    public AppResponse worksManage(@Valid @RequestBody PaintingWorkListDto dto ){
        AppResponse response = new AppResponse();
       List<PaintingWorks> list = worksService.getList(dto.getArtId(),dto.getRoomId(),dto.getStatus(),dto.getIsAdmin(),dto.getPageNo(),dto.getPageSize());
        List<PaintingWorksInfoVo> list1 = new ArrayList<>();
        PaintingWorksInfoVo vo = null;
        for (PaintingWorks works:list){
            vo = new PaintingWorksInfoVo();
            BeanUtils.copyProperties(works,vo);
            list1.add(vo);
        }
        response.setItems(list1);
        response.setTotals(worksService.getListTotals(dto.getArtId(),dto.getRoomId(),dto.getStatus()));
        return response;
    }

    @PostMapping("/auditStatus")
    @ApiOperation(value = "作品管理-列表数量(馆长)" ,notes = "")
    public AppResponse auditStatus(@Valid @RequestBody PaintingWorkListDto dto ){
        AppResponse response = new AppResponse();
        AuditStatusDto auditStatusDto  = new AuditStatusDto();
        auditStatusDto.setDsh(worksService.getListTotals(dto.getArtId(),dto.getRoomId(),0));
        auditStatusDto.setZpk(worksService.getListTotals(dto.getArtId(),dto.getRoomId(),1));
        auditStatusDto.setZlz(worksService.getListTotals(dto.getArtId(),dto.getRoomId(),2));
        auditStatusDto.setWtg(worksService.getListTotals(dto.getArtId(),dto.getRoomId(),-1));
        response.setItem(auditStatusDto);
        return response;
    }


    @PostMapping("/publish")
    @ApiOperation(value = "发布" ,notes = "")
    public AppResponse publish(@Valid @RequestBody PublishDto publishDto ){
        AppResponse response = new AppResponse();
        PaintingWorks paintingWorks = new PaintingWorks();
        BeanUtils.copyProperties(publishDto,paintingWorks);
        worksService.publish(paintingWorks);
        return response;
    }


    @PostMapping("/artWorksDetails")
    @ApiOperation(value = "美术馆作品详情列表(美术馆ID 选了房间也可以选传 状态，分页参数)" ,notes = "")
    public AppResponse artWorksDetails(@Valid @RequestBody ArtWorksDetailsDto detailsDto ){
        AppResponse response = new AppResponse();
        response.setItems(worksService.artWorksDetails(detailsDto.getArtId(),detailsDto.getRoomId(),detailsDto.getUserId(), detailsDto.getStatus(),detailsDto.getPageNo(),detailsDto.getPageSize()));
        return response;
    }

    @PostMapping("/batchDelete")
    @ApiOperation(value = "批量删除" ,notes = "")
    public AppResponse batchDelete(@Valid @RequestBody BatchDeleteDto deleteDto ){
        AppResponse response = new AppResponse();
        worksService.batchDelete(deleteDto.getArtId(),deleteDto.getIds());
        return response;
    }



    @PostMapping("/praises")
    @ApiOperation(value = "喜欢" ,notes = "")
    public AppResponse batchDelete(@Valid @RequestBody PaintingWorksDto worksDto ){
        AppResponse response = new AppResponse();
        praisesService.isPraises(worksDto.getWorkId(),worksDto.getUserId());
        return response;
    }


    @PostMapping("/addShows")
    @ApiOperation(value = "增加浏览量" ,notes = "")
    public AppResponse addShows(@Valid @RequestBody PaintingWorksDto worksDto ){
        AppResponse response = new AppResponse();
        worksService.addShows(worksDto.getUserId());
        return response;
    }


    @PostMapping("/updateWorkRoom")
    @ApiOperation(value = "作品修改展区" ,notes = "")
    public AppResponse updateRoom(@Valid @RequestBody PaintingWorksDto worksDto ){
        AppResponse response = new AppResponse();
        worksService.updateRoom(worksDto.getWorkId(),worksDto.getRoomId());
        return response;
    }

}

